package chamber.zero.file;

import chamber.zero.guice.Default;
import com.google.common.io.Files;
import com.google.inject.Inject;
import util.Resource;

import java.io.File;
import java.nio.charset.Charset;

/**
 * Created by Gerardo on 12/3/13.
 */
public class TextFileFactory implements FileFactory {
    private final Charset charset;

    @Inject
    public TextFileFactory(@Default final Charset charset) {
        this.charset = charset;
    }

    @Override
    public TextFile create(final Resource resource) {
        File file = new File(resource.get());
        return new TextFileImpl(Files.newReaderSupplier(file, charset), Files.newWriterSupplier(file, charset));
    }
}
